﻿using System.Collections.Generic;
using System.Linq;
using SilenthinkContract.Domain;

namespace Web.Areas.My.Models
{
    public class AddressControllerModel
    {
        public class Index
        {
            public IList<Location> Locations { get; set; }
            public IList<UserAddress> Addresses { get; set; }
            public string JsonData { get; set; }
            public string GetLocationName(string areaCode)
            {
                var provinceCode = areaCode.Substring(0, 2);
                var province = Locations.FirstOrDefault(o => o.LocationCode == provinceCode);
                var provinceName = province != null ? province.LocationName : string.Empty;

                var cityCode = areaCode.Substring(0, 4);
                var city = Locations.FirstOrDefault(o => o.LocationCode == cityCode);
                var cityName = city != null ? city.LocationName : string.Empty;

                var area = Locations.FirstOrDefault(o => o.LocationCode == areaCode||o.LocationCode == areaCode+"000000");
                var areaName = area != null ? area.LocationName : string.Empty;

                return string.Format("{0} {1} {2}", provinceName, cityName, areaName);

            }

        }
    }
}